<template>
	<view class="mine_set_view">
		<view class="sy_hang">
			<view class="s_left">
				姓名
			</view>
			<view class="r_left">
				<input class="m_input" type="text" v-model="realname" placeholder="请输入姓名"/>
			</view>
		</view>
		<view class="sy_hang">
			<view class="s_left">
				性别
			</view>
			<view class="r_left" @click="showPopXB">
				<!-- <input class="m_input" type="text" v-model="gender" placeholder="请输入性别"/> -->
				{{gender == 1 ? '男':'女'}} <image src="../../static/mine/mjt2.png" class="mjt1_img"></image>
			</view>
		</view>
		<view class="sy_hang">
			<view class="s_left">
				身高(cm)
			</view>
			<view class="r_left">
				<input class="m_input" type="text" v-model="height" placeholder="请输入身高"/>
			</view>
		</view>
		<view class="sy_hang">
			<view class="s_left">
				体重(kg)
			</view>
			<view class="r_left">
				<input class="m_input" type="text" v-model="weight" placeholder="请输入体重"/>
			</view>
		</view>
		<view class="sy_hang">
			<view class="s_left">
				手机号
			</view>
			<view class="r_left">
				<input class="m_input" type="text" v-model="mobile" placeholder="请输入手机号码"/>
			</view>
		</view>
		<view class="sy_hang">
			<view class="s_left">
				邮箱
			</view>
			<view class="r_left">
				<input class="m_input" type="text" v-model="email" placeholder="请输入您的邮箱"/>
			</view>
		</view>
		<view class="sy_hang">
			<view class="s_left">
				是否有重大疾病史
			</view>
			<view class="r_left" @click="showPop">
				{{jbList[jbListSel] ? jbList[jbListSel].name : ''}} <image src="../../static/mine/mjt2.png" class="mjt1_img"></image>
			</view>
		</view>
		<view class="pub_bottom_sub">
			<view class="sub_btn" @click="submit">
				保存
			</view>
		</view>
		<uni-popup ref="jbPopup" type="bottom">
			<view class="pop_box">
				<view class="pop_item" v-for="(item,key) in jbList" @click="changeC(item,key)">
					{{item.name}}
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="xbPopup" type="bottom">
			<view class="pop_box">
				<view class="pop_item" @click="changeXB('1')">
					男
				</view>
				<view class="pop_item" @click="changeXB('0')">
					女
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				jbList:[
					{name:"否",type:'0'},
					{name:"是",type:'1'}
				],
				jbListSel:0,
				realname:"",
				gender:'0',
				height:"",
				weight:"",
				mobile:"",
				email:"",
				jbListSel:"",
			};
		},
		computed:{
			userInfo(){
				return this.$store.state.userInfo
			},
			baseUrl(){
				return this.$store.state.baseUrl
			}
		},
		onHide() {
			this.$refs.jbPopup.close()
		},
		onShow() {
			console.log(this.userInfo,"this.userInfo---97")
			
			
		},
		mounted() {
			this.$resetUserInfo(()=>{
				this.realname = this.userInfo.realname;
				this.gender= this.userInfo.gender;
				this.height= this.userInfo.height;
				this.weight = this.userInfo.weight;
				this.mobile= this.userInfo.mobile;
				this.email= this.userInfo.email;
				this.jbListSel= this.userInfo.disease||0;
			})
			
		},
		methods:{
			changeC(item,key){
				this.jbListSel = key;
				this.$refs.jbPopup.close()
			},
			changeXB(el){
				this.gender = el;
				this.$refs.xbPopup.close()
			},
			showPop(){
				this.$refs.jbPopup.open()
			},
			showPopXB(){
				this.$refs.xbPopup.open()
			},
			submit(){
				if(this.mobile && !/^1[23456789]\d{9}$/.test(this.mobile)){
					this.$msg("请输入正确手机号");
					return false
				}
				if(this.email && !/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this.email)){
					this.$msg("请输入正确邮箱");
					return false
				}
				if(!this.realname){
					this.$msg("请输入您的真实姓名");
					return false
				}
				if(!this.gender){
					this.$msg("请输入您的性别");
					return false
				}

				let dataL = {
					realname:this.realname,
					gender:this.gender,
					height:this.height || "",
					weight:this.weight || "",
					mobile:this.mobile || "",
					email:this.email || "",
					disease:this.jbList[this.jbListSel].type
				}
				this.$queryApi("post","/user.user/update", dataL, res => {
					console.log(res,"login")
					this.$resetUserInfo(()=>{
						setTimeout(()=>{
							uni.navigateBack()
						},500)
						
					});
				})
			}
		}
	}
</script>

<style lang="scss">
	.pub_bottom_sub{
		background-color: #fff;
		position: fixed;
		left: 0;
		bottom: 0;
		padding: 14rpx 26rpx 66rpx 26rpx;
		box-sizing: border-box;
		width: 750rpx;
		.sub_btn{
			background: linear-gradient( 270deg, #3567D9 0%, #3677F6 100%);
			color: #fff;
			text-align: center;
			padding: 20rpx 0;
			border-radius: 60rpx;
			
		}
	}
.mine_set_view{
	padding: 4rpx 30rpx 60rpx 32rpx;
	box-sizing: border-box;
	min-height: 100vh;
	background-color: #fff;
	.pop_box{
		.pop_item{
			padding: 26rpx 0;
			background-color: #fff;
			text-align: center;
			&+.pop_item{
				border-top: 1rpx solid #f6f6f6;
			}
		}
	}
	.sy_hang{
		display: flex;
		justify-content: space-between;
		border-bottom: 1rpx solid #F6F6F6;
		padding: 30rpx 0;
		.s_left{
			color: #3D3D3D;
			font-size: 28rpx;
		}
		.r_left{
			display: inline-flex;
			align-items: center;
			font-size: 28rpx;
			.m_input{
				text-align: right;
				font-size: 28rpx;
			}
			.mjt1_img{
				width: 32rpx;
				height: 32rpx;
				margin-left: 16rpx;
				position: relative;
				top: 2rpx;
			}
		}
	}
}
</style>
